package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.BuyFirstCollection;
import com.sc.nft.entity.RushBuyCollection;
import com.sc.nft.entity.vo.RushBuyCollectionsListVO;
import com.sc.nft.mapper.RushBuyCollectionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_rush_buy_collection)数据DAO
 *
 * @author Sun
 * @since 2022-08-19 11:31:12
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class RushBuyCollectionDao extends ServiceImpl<RushBuyCollectionMapper, RushBuyCollection> {

    public List<RushBuyCollection> selectByProductId(Long productId) {
        LambdaQueryWrapper<RushBuyCollection> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(RushBuyCollection::getProductId,productId);
        return list(wrapper);
    }

    public RushBuyCollection selectByProductIdAndCollectionId(Long productId, Long collectionId) {
        LambdaQueryWrapper<RushBuyCollection> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RushBuyCollection::getProductId,productId);
        wrapper.eq(RushBuyCollection::getCollectionBuyFirstId,collectionId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public List<RushBuyCollectionsListVO> rushBuyCollectionsList(Long id) {
        return baseMapper.rushBuyCollectionsList(id);
    }

    public Boolean getIsExistByProductId(Long productId) {
        LambdaQueryWrapper<RushBuyCollection> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RushBuyCollection::getProductId, productId);
        return count(wrapper) > 0;
    }
}